/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/

const promiseFn = (string) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(string);
    }, 10);
  });
};

promiseFn("hello ")
  .then((res) => {
    return promiseFn(res + "lagou ");
  })
  .then((res) => {
    return promiseFn(res + "I ♥ U ");
  })
  .then((res) => {
    console.log(res);
  });

  
// generotor 的实现方式

// function* generator() {
//   const res1 = yield promiseFn("hello ");
//   const res2 = yield promiseFn("lagou ");
//   const res3 = yield promiseFn("I ♥ U ");
//   console.log(res1 + res2 + res3);
// }

// const g = generator();

// function co(g) {

//   const result = g.next()
  
//   function monadGenerator(result) {
//     if (result.done) return result.value;
//     result.value.then(res=>monadGenerator(g.next(res)))
//   }

//   monadGenerator(result);
// }

// co(g)